package com.hspedu.try_;

public class TryCatchDetail02 {
    public static void main(String[] args) {
        //多个异常捕获子类异常写前面，父类异常写后面
        try {
            Person person = new Person();
            person = null;
            System.out.println(person.getName());//NullPointerException
            int n1 = 10;
            int n2 = 0;
            int res = n1 / n2;//ArithmeticException
        } catch (NullPointerException e) {
            System.out.println("空指针异常" + e.getMessage());
        } catch (ArithmeticException e) {
            System.out.println("算数异常" + e.getMessage());
        } catch (Exception e) {
            System.out.println(e.getMessage());
        } finally {
        }
    }
}


class Person {
    private String name = "jack";

    public String getName() {
        return name;
    }
}